from RedisClient import RedisClient


class RedisQueue(object):

    def __init__(self, name):
        self.client = RedisClient()
        self.name = name

    def push(self, *values):
        return self.client.get_redis().lpush(self.name, *values)

    def pop(self):
        return self.client.get_redis().brpop(self.name, 0)[1]

    def len(self):
        return self.client.get_redis().llen(self.name)

    def clear(self):
        return self.client.get_redis().ltrim(self.name, 1, 0)


import time

if __name__ == '__main__':
    my_queue = RedisQueue('my_queue')

    my_queue.push("1", "2", '3', '4')

    # while True:
    #     print('len=', my_queue.len())
    #     print(my_queue.pop())
    #
    #     time.sleep(1)
    #
    #     if my_queue.len() == 0:
    #         my_queue.push("1", "2", '3', '4')

    my_queue.clear()
    print(my_queue.len())
